//
//  YSMeYaoCzViewController.m
//  YouSheng
//
//  Created by Mac on 16/8/29.
//  Copyright © 2016年 FanShuHan. All rights reserved.
//

#import "YSMeYaoCzViewController.h"
#import "YSOnlineRechargeViewController.h"
#import <Masonry.h>

#define YSBJColorLan [UIColor colorWithRed:78/255.0 green:204/255.0 blue:190/255.0 alpha:1]
#define YSBJColorHui [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1]

@interface YSMeYaoCzViewController ()

@property(nonatomic,weak) UITextField *khTF;

@end

@implementation YSMeYaoCzViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.view.backgroundColor = YSBJColorHui;
    self.title = self.navTitle;
    self.haoma = 13312345678;
    self.qian = 100;
    
    [self setupUI];
}


//UI搭建
- (void)setupUI {
    //余额
    UILabel *yueLab = [[UILabel alloc] init];
    yueLab.text = @"余额";
    yueLab.textColor = [UIColor grayColor];
    yueLab.font = [UIFont systemFontOfSize:20];
    
    [self.view addSubview:yueLab];
    
    [yueLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(84);
        make.centerX.equalTo(self.view);
        
    }];
    
    //手机号码
    UILabel *numLab = [[UILabel alloc] init];
    numLab.text = [NSString stringWithFormat:@"绑定号码: %.0f",self.haoma];
    numLab.textColor = [UIColor grayColor];
    numLab.font = [UIFont systemFontOfSize:14];
    
    [self.view addSubview:numLab];
    
    [numLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(yueLab.mas_bottom).offset(15);
        make.centerX.equalTo(self.view);
    }];
    
    //余额数值
    UILabel *qianLab = [[UILabel alloc] init];
    qianLab.text = [NSString stringWithFormat:@"%.2f",self.qian];
    qianLab.textColor = YSBJColorLan;
    qianLab.font = [UIFont systemFontOfSize:40];
    
    [self.view addSubview:qianLab];
    
    [qianLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(numLab.mas_bottom).offset(25);
        make.centerX.equalTo(self.view);
    }];
    
//    //套餐充值
//    UILabel *tcLab = [[UILabel alloc] init];
//    tcLab.text = @"套餐充值";
//    tcLab.textColor = [UIColor grayColor];
//    tcLab.font = [UIFont systemFontOfSize:20];
//    
//    [self.view addSubview:tcLab];
//    
//    [tcLab mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(qianLab.mas_bottom).offset(20);
//        make.centerX.equalTo(self.view);
//    }];
    
    //充值卡充值view
    UIView *view1 = [[UIView alloc] init];
//    view.backgroundColor = [UIColor whiteColor];
    
    self.View1 = view1;
    [self.view addSubview:view1];
    
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(qianLab.mas_bottom).offset(60);
        make.left.equalTo(self.view).offset(20);
        make.right.equalTo(self.view).offset(-20);
        make.height.mas_equalTo(250);
    }];
    
    //说明label1
    UILabel *smLab1 = [[UILabel alloc] init];
    smLab1.text = @"刮开充值卡上的密码层充值";
    smLab1.textColor = [UIColor grayColor];
    smLab1.font = [UIFont systemFontOfSize:18];
    
    [view1 addSubview:smLab1];
    
    [smLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view1.mas_top).offset(20);
        make.centerX.equalTo(view1);
    }];
    
    //说明label2
    UILabel *smLab2 = [[UILabel alloc] init];
    smLab2.text = @"充值金额需要1-5分钟到账";
    smLab2.textColor = [UIColor grayColor];
    smLab2.font = [UIFont systemFontOfSize:18];
    
    [view1 addSubview:smLab2];
    
    [smLab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(smLab1.mas_bottom).offset(5);
        make.centerX.equalTo(view1);
    }];
    
    //填写卡号
    UITextField *khTF = [[UITextField alloc] init];
    self.khTF = khTF;
    khTF.layer.cornerRadius = 5;
    khTF.placeholder = @"请输入充值卡密码";
    khTF.keyboardType = UIKeyboardTypeDefault;
    khTF.backgroundColor = [UIColor whiteColor];
    khTF.borderStyle = UITextBorderStyleRoundedRect;
    
    [view1 addSubview:khTF];
    
    [khTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(smLab2.mas_bottom).offset(20);
        make.left.equalTo(view1);
        make.right.equalTo(view1);
        make.height.mas_equalTo(40);
    }];
    
    //在线充值按钮
    UIButton *zxccBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    zxccBtn.titleLabel.font = [UIFont systemFontOfSize:14];
//    [zxccBtn setTitle:@"在线充值" forState:UIControlStateNormal];
    [zxccBtn setTitle:@"在线充值" forState:UIControlStateNormal];
    [zxccBtn setTitleColor:YSBJColorLan forState:UIControlStateNormal];
    [zxccBtn addTarget:self action:@selector(zxccBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    NSMutableAttributedString *str1 = [[NSMutableAttributedString alloc] initWithString:@"在线充值"];
    NSRange strRange1 = {0,[str1 length]};
    //设置下划线范围
    [str1 addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:strRange1];
    //设置下划线颜色
    [str1 addAttribute:NSUnderlineColorAttributeName value:YSBJColorLan range:strRange1];
    //设置文字颜色
    [str1 addAttribute:NSForegroundColorAttributeName value:YSBJColorLan  range:strRange1];
    //将下划线绘制到按钮上
    [zxccBtn setAttributedTitle:str1 forState:UIControlStateNormal];
    
    [view1 addSubview:zxccBtn];
    
    [zxccBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(khTF.mas_bottom).offset(0);
        make.right.equalTo(view1);
    }];
    
    //充值按钮
    UIButton *czBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    czBtn.layer.cornerRadius = 5;
    [czBtn setTitle:@"充值" forState:UIControlStateNormal];
    [czBtn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    [czBtn setBackgroundColor:YSBJColorLan];
    
    [czBtn addTarget:self action:@selector(czBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:czBtn];
    
    [czBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.mas_bottom).offset(-64);
        make.left.equalTo(self.view).offset(20);
        make.right.equalTo(self.view).offset(-20);
        make.height.mas_equalTo(44);
    }];

}

//充值按钮点击
- (void)czBtnClick {
    NSLog(@"点击了充值按钮");
}

//在线充值按钮点击
- (void)zxccBtnClick:(UIButton *)button {
    NSLog(@"点击了在线充值");
    YSOnlineRechargeViewController *onlVC = [[YSOnlineRechargeViewController alloc] init];
    onlVC.navTitle = button.titleLabel.text;
    
    [self.navigationController pushViewController:onlVC animated:YES];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.khTF resignFirstResponder];
}


@end
